<%@ page language="java" import="com.alibaba.fastjson.JSONArray" pageEncoding="UTF-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="okhttp3.*" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.concurrent.TimeUnit" %>
<%--流程退回调用QMS接口--%>
<%
    JSONArray paramList = new JSONArray();
    JSONObject dataJson = new JSONObject();
    dataJson.put("processId", "20230831001");
    dataJson.put("planId", "20230831009");
    dataJson.put("payType", "预付款");
    dataJson.put("isPur", "0");
    dataJson.put("currency", "RMB");
    dataJson.put("payAmount", 1000);
    dataJson.put("payTime", "2023-08-31");
    dataJson.put("payBank", "苏州银行");
    dataJson.put("payAccount", "1111222223333");
    dataJson.put("holder", "中环领先");
    dataJson.put("secondParty", "苏州测试公司");
    dataJson.put("bankStatementId", "20230831PX001");
    paramList.add(dataJson);
    JSONObject paramsJson = new JSONObject();
    paramsJson.put("funData",paramList);
    out.println(">>>>>WeaXmyksqlcPMPAction>>>>>paramsJson=" + paramsJson+"<br/>");
    JSONObject resultJson = fundPlan(paramsJson);
    out.println(">>>>>测试接口>>>>>resultJson=" + resultJson+ "<br/>");
%>

<%!

    private static final String URL = "http://10.193.221.95:8080";

    private static final Map<String, String> STRING_MAP = new HashMap();

    static {
        STRING_MAP.put("FundPlan", "/jeecg-boot/srm/oa/fundPlan");
        STRING_MAP.put("ProjFund", "/jeecg-boot/srm/oa/projFund");
    }

    public static JSONObject sendOKHttpRequest(String apiType,String params) {
        JSONObject resultJson = new JSONObject();
        String code = "fail";
        String message = "";
        String apiUrl = URL + Util.null2String(STRING_MAP.get(apiType));
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .connectTimeout(60, TimeUnit.SECONDS)
                    .readTimeout(60, TimeUnit.SECONDS)
                    .writeTimeout(60, TimeUnit.SECONDS)
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, params);
            Request request = new Request.Builder()
                    .url(apiUrl)
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
            String result = Util.null2String(response.body().string());
            if (!"".equals(result)) {
                resultJson = JSONObject.parseObject(result);
                code = "success";
            } else {
                message = "response result is null";
            }
        } catch (Exception e) {
            message = "response timeout";
            e.printStackTrace();
        }
        resultJson.put("code", code);
        resultJson.put("message", message);
        return resultJson;
    }

    /**
     * 付款信息推送接口
     *
     * @param content
     * @return
     */
    public static JSONObject fundPlan(JSONObject content) {
        return sendOKHttpRequest("FundPlan", content.toJSONString());
    }

    /**
     * 付款信息推送接口
     *
     * @param content
     * @return
     */
    public static JSONObject projFund(JSONObject content) {
        return sendOKHttpRequest("ProjFund", content.toJSONString());
    }

    /**
     * 返回yyyy-MM-dd
     *
     * @param datestr
     * @return
     */
    public static String formatDateToOA(String datestr) {
        String formatTime = "";
        if (!"".equals(datestr) && Util.getIntValue(datestr,-1)>0) {
            try {
                SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd");
                Date date1 = date.parse(datestr);
                formatTime = new SimpleDateFormat("yyyy-MM-dd").format(date1);
            } catch (ParseException e) {
                formatTime = datestr;
            }
        }
        return formatTime;
    }

    /**
     * 返回yyyyMMdd
     *
     * @param datestr
     * @return
     */
    public static String formatDateToSAP(String datestr) {
        String formatTime = "";
        if (!"".equals(datestr) && Util.getIntValue(datestr,-1)<0) {
            try {
                SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
                Date date1 = date.parse(datestr);
                formatTime = new SimpleDateFormat("yyyyMMdd").format(date1);
            } catch (ParseException e) {
                formatTime = datestr;
            }
        }
        return formatTime;
    }

%>




